package com.eduhzy.ttw.work.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.contract.WorkHomeContract;
import com.eduhzy.ttw.work.mvp.model.WorkHomeModel;
import com.eduhzy.ttw.work.mvp.model.entity.WorkListData;
import com.jess.arms.di.scope.ActivityScope;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-1 15:42:29
 */
@Module
public class WorkHomeModule {
    private WorkHomeContract.View view;

    /**
     * 构建WorkHomeModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public WorkHomeModule(WorkHomeContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    WorkHomeContract.View provideWorkHomeView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    WorkHomeContract.Model provideWorkHomeModel(WorkHomeModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<WorkListData, AutoBaseViewHolder> providerAdapter(List<WorkListData> lists) {
        return new BaseQuickAdapter<WorkListData, AutoBaseViewHolder>(R.layout.work_rv_item_work, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, WorkListData item) {
                helper.setText(R.id.tv_title, item.getTitle());
                helper.setText(R.id.tv_time, TimeUtils.millis2String(item.getPushTime(), new SimpleDateFormat("MM月dd日 HH:mm")));
                helper.setText(R.id.tv_status, item.getWorkStatus() == 1 ? "进行中" : "已完成");
                helper.setTextColor(R.id.tv_status, item.getWorkStatus() == 1
                        ?mContext.getResources().getColor(R.color.public_green)
                        : mContext.getResources().getColor(R.color.public_color_979797));
            }
        };

    }

    @ActivityScope
    @Provides
    List<WorkListData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new LinearLayoutManager(view.getActivity());
    }


}